
<title>工资统计报表 - 报表管理</title>

<div class="page-header">
	<h1>
		报表管理 <small> <i class="ace-icon fa fa-angle-double-right"></i>
			工资统计报表
		</small>
	</h1>
</div>

<div class="row">
	<div class="col-xs-12">

		<div class="widget-box">
			<div class="widget-header"><h4 class="widget-title">选择统计条件</h4></div>

			<div class="widget-body" style="display: block;">
				<form id="conditionForm">
					<div class="widget-main">
						<div class="row">
							<div class="col-md-2  col-md-push-1">
								<label>年度</label><select id="yearList"
									class="year-list form-control"></select>
							</div>
							<div class="col-md-2  col-md-push-1">
								<label>月度</label><select id="monthList"
									class="month-list form-control"></select>
							</div>
							<div class="col-md-2  col-md-push-1">
								<label>部门</label><select id="depList"
									class="dep-list form-control"></select>
							</div>
							<div class="col-md-2  col-md-push-1">
								<label>员工</label><select id="empList" class="emp-list form-control"><option value="null">请指定部门</option></select> <br />
							</div>
							
							<div class="col-md-2  col-md-push-1" style="padding-top:15px">
								<input type="submit" value="查询" class="btn btn-primary" />

								<input type="button" id="btnPrint" class="btn btn-primary" value="导出" />
							</div>
							
							<div class="col-md-5  col-md-push-1">
								<label>统计范畴： </label> <input id="comChk" type="checkbox"
									value="com" />公司&nbsp;&nbsp; <input id="depChk"
									type="checkbox" value="dep" />部门&nbsp;&nbsp; <input
									id="empChk" type="checkbox" value="emp" />员工
							</div>

						</div>
					</div>
				</form>
			</div>
		</div>

		<br />
		<div id="printContent">
			<div id="comHeader"></div>
			<div id="depHeader"></div>
			<div id="empHeader"></div>
		</div>

	</div>
</div>
<script type="text/javascript">
	var scripts = [ null, "lib/assets/js/chosen.jquery.js", null ];
	
	var printdiv = function () {
		var printData = document.getElementById("printContent").innerHTML;
		//var oldstr = document.body.innerHTML;
		document.body.innerHTML = "<html><head></head><body>" + printData + "</body>";
		window.print();
		//document.body.innerHTML = oldstr;
		location.reload();
	};
	
	$('.page-content-area')
			.ace_ajax(
					'loadScripts',
					scripts,
					function() {
						
						/* 导出按钮局部打印Chrome */
					    $("#btnPrint").bind("click", function() {printdiv()});

						/* 动态加载[年度][月度]列表 */
						$("#yearList").append(
								"<option value=\"null\">请选择</option>");
						for (var i = 2010; i <= 2050; i++) {
							$("#yearList").append(
									"<option value=\"" + i + "\">" + i
											+ "年</option>");
						}
						$(".year-list").chosen();
						
						$("#monthList").append(
								"<option value=\"null\">请选择</option>");
						for (var i = 1; i < 13; i++) {
							$("#monthList").append(
									"<option value=\"" + i + "\">" + i
											+ "月</option>");
						}
						$(".month-list").chosen();

						/* 动态加载[部门]列表 */
						$.ajax({
									type : "GET",
									url : "depliyi/get",
									success : function(data) {
										var options = data.response;
										$("#depList").empty();
										$("#depList").append("<option value=\"null\">请选择</option>");
										for(var i=0;i<options.length;i++){
											var option = options[i];
											$("#depList").append("<option value=\"" + 
													option.dep_id + "\">" + 
													option.dep_name + "</option>");
										}
										$(".dep-list").chosen();
									}
						});
						
						/* 级联部门选中 加载员工下拉 */
						$(".emp-list").chosen();
						$("#depList")
								.bind(
										"change",
										function() {
											var depId = $("#depList").val();
											$
													.ajax({
														type : "GET",
														url : "empliyi/get?depId=" + depId,
														success : function(data) {
															var options = data.response;
															$("#empList")
																	.empty();
															for (var i = 0; i < options.length; i++) {
																var option = options[i];
																$("#empList")
																		.append(
																				"<option value=\"" + 
												option.emp_id + "\">"
																						+ option.emp_name
																						+ "</option>");
															}
															$(".emp-list").chosen("destroy");
															$(".emp-list").chosen();
														}
													});
										});

						/* 查询参数为空的表单验证 和 异步加载结果 */
						$("#conditionForm")
								.bind(
										"submit",
										function() {
											var err = "";

											if ($("#yearList").val() == "null") {
												err += "- 亲，请指定 [年度] 信息 - \n";
											}
											if ($("#monthList").val() == "null") {
												err += "- 亲，请指定 [月度] 信息 - \n";
											}
											if ($("#depChk").attr("checked") == "checked"
													&& $("#depList").val() == "null") {
												err += "- 亲，请指定 [部门] 信息 - \n";
											}
											if ($("#empChk").attr("checked") == "checked"
													&& $("#empList").val() == "null") {
												err += "- 亲，请指定 [员工] 信息 - \n";
											}

											if (err == "") {
												$("#comHeader").empty();
												$("#depHeader").empty();
												$("#empHeader").empty();
												/* 异步加载查询结果 */
												if ($("#comChk")
														.prop("checked")) {
													var year = $("#yearList").val();
													var month = $("#monthList").val();
													$
															.ajax({
																type : "GET",
																url : "salarystatements/com?year=" + year + "&month=" + month,
																success : function(
																		data) {
																	var trs = data.response;
																	$(
																			"#comHeader")
																			.append(
																					"<label>公司 年度/月度 工资统计报表</label><table id=\"showCom\" class=\"table table-bordered table-hover text-center\"></table>");
																	for (var i = 0; i < trs.length; i++) {
																		var tr = trs[i];
																		/* 生成表头 */
																		if (i == 0) {
																			$(
																					"#showCom")
																					.append(
																							"<thead>"
																									+ "<tr><th>"
																									+ tr.year + "/" + tr.month
																									+ "</th><th>"
																									+ tr.totalSalary
																									+ "</th><th>"
																									+ tr.avgSalary
																									+ "</th><th>"
																									+ tr.minSalary
																									+ "</th><th>"
																									+ tr.maxSalary
																									+ "</th>"
																									+ "</thead>");
																		}
																		/* 生成数据 */
																		else {
																			$(
																					"#showCom")
																					.append(
																							"<tbody>"
																									+ "<tr><td>"
																									+ tr.year + "年" + tr.month + "月"
																									+ "</td><td>"
																									+ tr.totalSalary
																									+ "</td><td>"
																									+ tr.avgSalary
																									+ "</td><td>"
																									+ tr.minSalary
																									+ "</td><td>"
																									+ tr.maxSalary
																									+ "</td>"
																									+ "</tbody>");
																		}
																	}
																}
															});
												}

												if ($("#depChk")
														.prop("checked")) {
													var year = $("#yearList").val();
													var month = $("#monthList").val();
													var depId = $("#depList").val();
													$
															.ajax({
																type : "GET",
																url : "salarystatements/dep?year=" + year + "&month=" + month + "&depId=" + depId,
																success : function(
																		data) {
																	var trs = data.response;
																	$(
																			"#depHeader")
																			.append(
																					"<label>部门 年度/月度 工资统计报表</label><table id=\"showDep\" class=\"table table-bordered table-hover text-center\"></table>");
																	for (var i = 0; i < trs.length; i++) {
																		var tr = trs[i];
																		/* 生成表头 */
																		if (i == 0) {
																			$(
																					"#showDep")
																					.append(
																							"<thead>"
																									+ "<tr><th>"
																									+ tr.depId
																									+ "</th><th>"
																									+ tr.depName
																									+ "</th><th>"
																									+ tr.year + "/" + tr.month
																									+ "</th><th>"
																									+ tr.totalBaseSalary
																									+ "</th><th>"
																									+ tr.avgBaseSalary
																									+ "</th><th>"
																									+ tr.minBaseSalary
																									+ "</th><th>"
																									+ tr.maxBaseSalary
																									+ "</th>"
																									+ "</thead>");
																		}
																		/* 生成数据 */
																		else {
																			$(
																					"#showDep")
																					.append(
																							"<tbody>"
																									+ "<tr><td>"
																									+ tr.depId
																									+ "</td><td>"
																									+ tr.depName
																									+ "</td><td>"
																									+ tr.year + "年" + tr.month + "月"
																									+ "</td><td>"
																									+ tr.totalBaseSalary
																									+ "</td><td>"
																									+ tr.avgBaseSalary
																									+ "</td><td>"
																									+ tr.minBaseSalary
																									+ "</td><td>"
																									+ tr.maxBaseSalary
																									+ "</td>"
																									+ "</tbody>");
																		}
																	}
																}
															});
												}

												if ($("#empChk")
														.prop("checked")) {
													var year = $("#yearList").val();
													var empId = $("#empList").val();
													$
															.ajax({
																type : "GET",
																url : "salarystatements/emp?year=" + year + "&empId=" + empId,
																success : function(
																		data) {
																	var trs = data.response;
																	var tag = "th";
																	$(
																			"#empHeader")
																			.append(
																					"<label>员工 年度 工资统计报表</label><table id=\"showEmp\" class=\"table table-bordered table-hover text-center\"></table>");
																	for (var i = 0; i < trs.length; i++) {
																		var tr = trs[i];
																		/* 生成表头 */
																		if (i == 0) {
																			$(
																					"#showEmp")
																					.append(
																							"<thead>"
																									+ "<tr><th>"
																									+ tr.empId
																									+ "</th><th>"
																									+ tr.empName
																									+ "</th><th>"
																									+ tr.year
																									+ "</th><th>"
																									+ tr.totalBaseSalary
																									+ "</th><th>"
																									+ tr.totalPension
																									+ "</th><th>"
																									+ tr.totalMedical
																									+ "</th><th>"
																									+ tr.totalHousingFund
																									+ "</th><th>"
																									+ tr.totalSickleaveHold
																									+ "</th><th>"
																									+ tr.totalOverworkSalary
																									+ "</th>"
																									+ "</thead>");
																		}
																		/* 生成数据 */
																		else {
																			$(
																					"#showEmp")
																					.append(
																							"<tbody>"
																									+ "<tr><td>"
																									+ tr.empId
																									+ "</td><td>"
																									+ tr.empName
																									+ "</td><td>"
																									+ tr.year + "年"
																									+ "</td><td>"
																									+ tr.totalBaseSalary
																									+ "</td><td>"
																									+ tr.totalPension
																									+ "</td><td>"
																									+ tr.totalMedical
																									+ "</td><td>"
																									+ tr.totalHousingFund
																									+ "</td><td>"
																									+ tr.totalSickleaveHold
																									+ "</td><td>"
																									+ tr.totalOverworkSalary
																									+ "</td>"
																									+ "</tbody>");
																		}
																	}
																}
															});
												}
												return false;
											} else {
												alert(err);
												return false;
											}
										});

					});
</script>